package com.bub.pay.core.manager.role.menu.impl;

import com.bub.pay.core.base.BaseManagerAbstract;
import com.bub.pay.core.dao.SysRolePermDao;
import com.bub.pay.core.entity.domain.SysRolePerm;
import com.bub.pay.core.manager.role.menu.RolePermManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleMenuManagerImpl extends BaseManagerAbstract<SysRolePerm, SysRolePermDao> implements RolePermManager {
    @Resource
    private SysRolePermDao sysRolePermDao;

   /* @Override
    @Transactional
    public int grant(List<RoleMenuVO> list, Long createId) {
        List<SysRoleMenu> batch = new ArrayList<>();
        Calendar c = Calendar.getInstance();
        list.stream().forEach(vo ->
                {
                    SysRoleMenu rm = new SysRoleMenu();
                    rm.setRoleId(vo.getRoleId());
                    bnSysRoleMenuDao.delete(rm);

                    Arrays.stream(vo.getMenus()).forEach(menu -> {
                        SysRoleMenu m = new SysRoleMenu();
                        m.setRoleId(vo.getRoleId());
                        m.setMenuId(menu);
                        m.setCreateId(createId);
                        m.setCreateDate(c.getTime());
                        m.setDelFlag(DeleteFlagEnum.using.flag);
                        batch.add(m);
                    });
                }

        );
        return 1;
    }*/

    @Override
    @Transactional
    public int grant(Long[] menus, Long RoleId, Long createId) {
        /*List<SysRoleMenu> batch = new ArrayList<>();
        Calendar c = Calendar.getInstance();
        Arrays.stream(menus).forEach(m -> {
            SysRoleMenu mr = new SysRoleMenu();
            mr.setRoleId(RoleId);
            mr.setMenuId(m);
            mr.setCreateId(createId);
            mr.setCreateDate(c.getTime());
            mr.setDelFlag(DeleteFlagEnum.using.flag);
            batch.add(mr);
        });*/
        return 1;/*this.getBaseMapper().insertList(batch);*/
    }

    @Override
    @Transactional
    public int reGrant(Long[] menus, Long RoleId, Long createId) {
        /*SysRoleMenu rm = new SysRoleMenu();
        rm.setRoleId(RoleId);
        bnSysRoleMenuDao.delete(rm);
        grant(menus, RoleId, createId);*/
        return 0;
    }

    @Override
    public int insertList(List<SysRolePerm> rolePerms) {
        return sysRolePermDao.insertList(rolePerms);
    }
}
